package ru.spb.osll.myfit.userchart;

import ru.spb.osll.myfit.util.parser.ILogParser;
import ru.spb.osll.myfit.util.parser.IResultSection;
import ru.spb.osll.myfit.util.parser.ResultSection;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * User: Artem Bukhonov
 * Email: nerzhulart@gmail.com
 * Date: 10.11.11
 * Time: 17:35
 */
public class SquareLogParser implements ILogParser {
  private List<IResultSection> m_results = new ArrayList<IResultSection>();
  private Pattern m_pattern = Pattern.compile(".*INFO.*x=(\\d*).*y=(\\d*).*");

  public SquareLogParser() {
    m_results.add(new ResultSection("Square"));
  }

  @Override
  public void infoLine(String line) {
    Matcher matcher = m_pattern.matcher(line);
    if (matcher.find()) {
      String x = matcher.group(1);
      String y = matcher.group(2);
      m_results.get(0).addRow(x, y);
    }
  }

  @Override
  public void errorLine(String line) {
  }

  @Override
  public List<IResultSection> getResults() {
    return m_results;
  }

  @Override
  public void reset() {
    m_results.clear();
  }
}
